/**
 *	Copyright (c) 1996-2010 Maxim Shklyar, kisla interactive, kisla.com 
 *	All rights reserved.
**/

package com.kisla.Xslidenav
{
	import flash.net.URLRequest;
	import flash.display.Loader;

	import flash.display.SimpleButton;
	import flash.events.MouseEvent;

	import flash.display.MovieClip;
	import flash.text.TextField;

	import com.kisla.contr.ControlEvent;


	public class Xnav extends MovieClip {

		private var conf_xml:XML;
		private var data_xml:XML;

		private var items_arr:Array = new Array();


// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

		public function Xnav() {}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

		public function init(cx:XML, dx:XML) {

			conf_xml = cx;
			data_xml = dx;

			var i:int = 0;
			for each(var sx:XML in data_xml.slides.s) {

				var ni = new nav_item;
				nav_item_cont.addChild( ni );
				ni.x = conf_xml.nav.@xd * i;
				ni.ind = i;
				ni.gotoAndStop("reg");
				i++;

				items_arr.push(ni);

				ni.addEventListener(MouseEvent.CLICK, nav_clicked);

			}

			next_btn.addEventListener(MouseEvent.CLICK, function(){	root.dispatchEvent(new ControlEvent(ControlEvent.NAV_NEXT));	});
			prev_btn.addEventListener(MouseEvent.CLICK, function(){	root.dispatchEvent(new ControlEvent(ControlEvent.NAV_PREV));	});

		}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

		private function nav_clicked(e:MouseEvent=null):void
		{
			root.dispatchEvent(new ControlEvent(ControlEvent.NAV_CLICKED, e.target.ind));
		}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

		public function upd_nav(curr_sl:int):void
		{
			for (var i:int=0; i<items_arr.length; i++)
				items_arr[i].gotoAndStop( i==curr_sl ? "sel" : "reg" );

			tot_tf.text = (curr_sl+1) + " of " + data_xml.slides.s.length();

			next_btn.visible = curr_sl<data_xml.slides.s.length()-1;
			prev_btn.visible = curr_sl>0;
		}

// ----	--------------------------------------------	--------------------------------------------	
// ----	--------------------------------------------	--------------------------------------------	

	}
}
